home *** CD-ROM | disk | FTP | other *** search
- // Header //
- //
- // FOSSIL
- //
- // Contents -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- //
- // A FOSSIL communications class
- //
- // Copyright (C) 1991 by J.R.Louvau
- // All rights reserved.
- //
- // License
- //
- // This source code is freely available, copyrighted material.
- // You are free to incorporate it into other software you are developing
- // in original or modified form. You may also distribute it in any way
- // you see fit, provided you follow these guidelines:
- // 1) The contents of the header (".hpp") and source (".cpp") remain
- // in their original form.
- // 2) You don't make a profit.
- // 3) Charging for a package you have developed which incorporates
- // these routines in BINARY (.obj, .exe, etc.) is fine, but you may
- // NOT include this SOURCE CODE in any for-profit package.
- //
- // Warranties, Liabilities, etc. ad nauseum
- //
- // None! It works on my compiler, hardware, modem, etc. If it works
- // for you, great... if not, well, that's why you got the source code -
- // so that YOU could fix it ;-) You can't get blood from a turnip,
- // and I'm a turnip. Help save the environment: starve a lawyer.
- //
- // Description
- //
- // A serial I/O interface library for use with a FOSSIL driver.
- //
- // End =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
- #ifndef __FOSSIL_HPP
- #define __FOSSIL_HPP
-
- #if __STDC__
- #define _Cdecl
- #else
- #define _Cdecl cdecl
- #endif
-
- // comment this out if you want pre-compiled headers
- // in Borland C++
-
- #ifdef __BCPLUSPLUS__
- #pragma hdrstop
- #endif
-
- // Interface Dependencies -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- //
- // End Interface Dependencies -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
- // Implementation Dependencies =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
- #include <stddef.h>
-
- // End Implementation Dependencies =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
- struct FosInfo
- {
- unsigned char maxfunc, // Maximum function # supported
- revision; // FOSSIL revision level
- };
-
- struct TimInfo
- {
- unsigned char intnum, // timer interrupt NUMBER
- ticpersec; // approx. ticks per second
- unsigned int mspertic; // approx. milliseconds per tick
- };
-
- struct FosData
- {
- unsigned int fdsize; // Structure size
- unsigned char specver; // FOSSIL spec version
- unsigned char drvlvl; // Driver rev level
- unsigned char far *drvid; // Pointer to ASCII ID
- unsigned int rxsize; // Input buffer size
- unsigned int rxavail; // Bytes avail (input)
- unsigned int txsize; // Output buffer size
- unsigned int txavail; // Bytes avail (output)
- unsigned char scnwid; // Screen width, chars
- unsigned char scnlen; // Screen height, chars
- unsigned int bdmask; // Baud rate mask
- unsigned char filler[2];
- };
-
- // Class //
-
- class FosIo
-
- // Description =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- //
- // Bitmasks, values, paramater conversions, etc.
- //
- // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- {
- public:
-
- // baudrate bitmasks
-
- enum _baudmask
- {
- bmask = 0x01e0, // mask
- b19k = 0x0000, // 19200
- b38k = 0x0020, // 38400
- b300 = 0x0040, // 300
- b600 = 0x0060, // 600
- b1200 = 0x0080, // 1200
- b2400 = 0x00a0, // 2400
- b4800 = 0x00c0, // 4800
- b9600 = 0x00e0, // 9600
- b57k = 0x0100, // 57600
- b115k = 0x0120 // 115200
- };
-
- // databits bitmasks
-
- enum _datamask
- {
- dmask = 0x0003, // mask
- eight = 0x0003, // 8
- seven = 0x0002, // 7
- six = 0x0001 // 6
- };
-
- // parity bitmasks
-
- enum _parimask
- {
- pmask = 0x0018, // mask
- none = 0x0000, // none
- even = 0x0018, // even
- odd = 0x0008, // odd
- space = 0x0010, // space
- mark = 0x0010 // mark
- };
-
- // stop-bit bitmasks
-
- enum
- {
- smask = 0x0004, // mask
- one = 0x0000, // 1
- two = 0x0004 // 2
- };
-
- // some easier-to-use combined definitions
-
- enum
- {
- N81 = none|eight|one,
- N82 = none|eight|two,
- O71 = odd|seven|one,
- E71 = even|seven|one,
- N71 = none|seven|one,
- O72 = odd|seven|two,
- E72 = even|seven|two,
- N72 = none|seven|two
- };
-
- // flow control, etc. bitmasks
-
- enum
- {
- localxon = 0x0001, // enable local xon/xoff
- localcts = 0x0002, // enable local cts/rts
- remotexon = 0x0008, // enable remote xon/xoff
- noflow = 0x0000 // disable all flow control
- };
-
- // line control and somesuch bitmasks
-
- enum
- {
- dtron = 0x0001, // raise dtr
- dtroff = 0x0000, // lower dtr
- brkon = 0x0001, // send break
- brkoff = 0x0000 // stop sending break
- };
-
- // status bitmasks
-
- enum
- {
- rxr = 0x0100, // data in receive buffer
- ovn = 0x0200, // recive buffer overrun
- txr = 0x2000, // transmit buffer has room
- txe = 0x4000, // transmit buffer is empty
- dcd = 0x0080 // data carrier detect
- };
-
- // constructor
-
- FosIo(); // default
-
- // destructor
-
- ~FosIo();
-
- // conversion functions
-
- unsigned int _Cdecl stringToSetup(signed char * _s);
- unsigned int _Cdecl valuesToSetup(unsigned long int _baudrate,
- unsigned char _databits,
- unsigned char _parity,
- unsigned char _stopbits);
- char * _Cdecl setupToString(unsigned int _setup, char * _s = 0);
- void _Cdecl setupToValues(unsigned int _setup,
- unsigned long int & _baudrate,
- unsigned char & _databits,
- unsigned char & _parity,
- unsigned char & _stopbits);
-
- ////
- //
- // Protected Stuff
- //
- ////
-
- protected:
-
- unsigned int commport,
- portmask;
-
- };
- // End =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
- // Class //
-
- class Fossil : public FosInfo, public TimInfo,
- public FosData, public FosIo
-
- // Description =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- //
- // The FOSSIL class
- //
- // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- {
- ////
- //
- // Public Stuff
- //
- ////
-
- public:
-
- // constructors
-
- _Cdecl Fossil();
- _Cdecl Fossil(unsigned int _port, unsigned int _cbrk = 0);
- _Cdecl Fossil(unsigned int _port, unsigned char _mask, unsigned int _cbrk = 0);
- _Cdecl Fossil(unsigned int _port, char * _initstr, unsigned int _cbrk = 0);
- _Cdecl Fossil(unsigned int _port, unsigned long int _baud, unsigned char _data,
- unsigned char _pari, unsigned char _stop, unsigned int _cbrk = 0);
-
- // destructor
-
- _Cdecl ~Fossil();
-
- // initialisation member functions
-
- unsigned int _Cdecl open(unsigned int _port, unsigned char _mask,
- unsigned int _cbrk = 0);
- unsigned int _Cdecl open(unsigned int _port, char * _initstr,
- unsigned int _cbrk = 0);
- unsigned int _Cdecl open(unsigned int _port, unsigned long int _baud,
- unsigned char _data, unsigned char _pari,
- unsigned char _stop, unsigned int _cbrk = 0);
-
- // de-initialisation member function
-
- void _Cdecl close();
-
- // fossil manipulation...
- // see notes in FOSSIL.CPP for more info.
-
- unsigned int _Cdecl set(unsigned char _mask);
- unsigned int _Cdecl putW(unsigned char _c);
- unsigned char _Cdecl getW();
- unsigned int _Cdecl status();
- unsigned char _Cdecl dtr(unsigned int _raise);
- void _Cdecl flushOut();
- void _Cdecl purgeOut();
- void _Cdecl purgeIn();
- unsigned int _Cdecl put(unsigned char _c);
- unsigned int _Cdecl peek();
- unsigned int _Cdecl peekKey();
- unsigned int _Cdecl getKey();
- void _Cdecl flow(unsigned char _mask);
- unsigned int _Cdecl control(unsigned char _mask);
- void _Cdecl gotoXY(unsigned char _row, unsigned char _col);
- void _Cdecl whereXY(unsigned char & _row, unsigned char & _col);
- void _Cdecl putANSI(unsigned char _c);
- void _Cdecl watchdog(unsigned int _enable);
- void _Cdecl putBIOS(unsigned char _c);
- unsigned int _Cdecl timerChain(unsigned int _insert, void (far * _f)());
- void _Cdecl reboot(unsigned int _warm);
- unsigned int _Cdecl read(void far * _buffer, unsigned int _count);
- unsigned int _Cdecl write(void far * _buffer, unsigned int _count);
- void _Cdecl brk(unsigned int _start);
- unsigned int _Cdecl installApi(unsigned char _code, void (far * _f)());
- unsigned int _Cdecl removeApi(unsigned char _code, void (far * _f)());
- unsigned int _Cdecl operator ! ();
- unsigned int _Cdecl carrier();
- unsigned int _Cdecl incoming();
- unsigned int _Cdecl mode();
- void _Cdecl info();
-
- ////
- //
- // Protected Stuff
- //
- ////
-
- protected:
-
- unsigned int foserr; // for internal error flags
-
- ////
- //
- // Private Stuff
- //
- ////
-
- private:
-
- unsigned char ctlcnt, // ^C counter if requested
- initialised; // non zero if FOSSIL is on
-
- // common initialisation subfunction
-
- unsigned int _Cdecl _initialise(unsigned char far * _countc = NULL);
-
- // common de-initialisation subfunction
-
- void _Cdecl _deInitialise();
-
- // low-level tick checker
-
- void _Cdecl _getTicks(TimInfo & T);
-
- // get fossil driver info subfunction
-
- unsigned int _Cdecl _info(FosData & _D);
- };
- // End =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
- #endif
-